package edu.ynu.se.xiecheng.achitectureclass.project.controller;

import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.common.service.LogicService;
import edu.ynu.se.xiecheng.achitectureclass.project.dao.DeviceDao;
import edu.ynu.se.xiecheng.achitectureclass.project.po.entity.Device;
import edu.ynu.se.xiecheng.achitectureclass.project.po.vo.DeviceVO;
import edu.ynu.se.xiecheng.achitectureclass.project.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/devices")
@Api(tags = "设备管理接口")
public class DeviceController extends LogicController<DeviceService, DeviceDao,Device, Long> {

    public DeviceController(DeviceService ls) {
        super(ls);
    }

    @Autowired
    private DeviceService deviceService;

    @GetMapping("/list")
    @ApiOperation("获取所有设备状态")
    public ResponseEntity<List<DeviceVO>> getAllDevices() {
        try {
            List<DeviceVO> devices = deviceService.getAllDevicesStatus();
            return ResponseEntity.ok(devices);
        } catch (Exception e) {
            log.error("获取设备列表失败", e);
            return ResponseEntity.internalServerError().build();
        }
    }

}
